<template>
    <div>
        <a-button class="mb12" type="primary" @click="add" v-if="hideBuquBtn()">新增</a-button>
        <list-table
            ref="table"
            :columns="columns"
            :request="loadData"
            :page-keys="['pageNo', 'pageSize', 'totalSize']"
            :show-page="false"
        >
            <div slot="actions" slot-scope="text, record" class="pub-table-list-action" v-if="hideBuquBtn()">
                <template>
                    <span v-if="record.code != 2" @click="edit(record)">编辑</span>
                    <span v-if="record.code != 2 && record.code != 1 && typeId*1!==14" @click="del(record)">删除</span>
                    <span v-if="record.code != 2 && record.code != 1 && typeId*1===14" @click="delTypesLabelFn(record)">删除</span>
                </template>
            </div>
        </list-table>
        <update class="vue" :visible.sync="visible" :form="form" :type-id="typeId" @ok="$refs.table.refresh()"></update>
    </div>
</template>

<script>
import { list, del,delTypesLabel} from '@/api/technical/config'
import update from './update'

export default {
    name: 'a' + Date.now(),
    components: {
        update
    },
    props: {
        // v-model绑定的数据
        columns: {
            type: Array,
            default: []
        },
        typeId: {
            type: [String, Number],
            default: null
        }
    },
    data() {
        return {
            form: {},
            visible: false,
            loadData: async (q) => await list({ ...q, type: this.typeId })
        }
    },
    methods: {
        del(record) {
            this.$delList3(
                del,
                (res) => {
                    this.$refs.table.refresh()
                },
                { id: record.id },
                null
            )
        },
       delTypesLabelFn(record){
           this.$delListHiden(
                delTypesLabel,
                (res) => {
                    this.$refs.table.refresh()
                },
                { id: record.id,type:this.typeId},
                null,
            )
       },  
        add() {
            this.form = { enabled: 1 }
            this.visible = true
        },
        edit(record) {
            this.form = { ...record }
            this.form.enabled = this.form.enabled ? 1 : 0
            this.visible = true
        }
    }
}
</script>